#pragma once

#include <rocksdb/compaction_filter.h>

#include <memory>
#include <string>
#include <vector>

#include "base_data_key_format.h"
#include "base_meta_value_format.h"

class BaseMetaFilter : public rocksdb::CompactionFilter {
 public:
  BaseMetaFilter() = default;
  bool Filter(int level, const rocksdb::Slice& key, const rocksdb::Slice& value,
              std::string* new_value, bool* value_changed) const override {
    int64_t unix_time;
    rocksdb::Env::Default()->GetCurrentTime(&unix_time);
    int32_t cur_time = static_cast<int32_t>(unix_time);
    ParsedBaseMetaValue parsed_base_meta_value(value);
    if (parsed_base_meta_value.timestamp() != 0 &&
        parsed_base_meta_value.timestamp() < cur_time &&
        parsed_base_meta_value.verison() < cur_time) {
      return true;
    }

    if (parsed_base_meta_value.count() == 0 &&
        parsed_base_meta_value.verison() < cur_time) {
      return true;
    }
    return false;
  }
  const char* Name() const override { return "BaseMetaFilter"; }
};